//
//  QualitycreationdetailsNBViewController.m
//  Gxj
//
//  Created by 💋索少杰 on 2017/10/20.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "QualitycreationdetailsNBViewController.h"
#import "QualitycreationdetailsTableViewNBCell.h"

@interface QualitycreationdetailsNBViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic, strong) UITableView * tableView;//

//导航条上拉隐藏下拉显示
@property (nonatomic, assign) CGFloat borderNum;
@property (nonatomic ,assign) NSInteger firstComeInNum;
//@property (nonatomic, strong) UIButton *navTitleBtn;
@property (nonatomic, strong) UIView *navTitleView;

@property(nonatomic, strong) UILabel * navTitleLbl;
@property(nonatomic, strong) UIView * headView;


@end

@implementation QualitycreationdetailsNBViewController

- (void)viewDidLoad {
    
    self.view.backgroundColor=[UIColor whiteColor];
    [super viewDidLoad];
    
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;  // 侧滑返回
    //导航条左边按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"fanhui1"] style:UIBarButtonItemStyleDone target:self action:@selector(clickLeftBarButton)];
    //导航条右边按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"xialagenduo"] style:UIBarButtonItemStyleDone target:self action:@selector(clickRightButton)];
    
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]};
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg"]forBarMetrics:UIBarMetricsDefault];
    
    
    /* 导航标题**/
    // 导航背景视图
    UIView *navBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidthScale(200), kHeightScale(30))];
    self.navigationItem.titleView = navBackView;
    
    UILabel *titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kWidthScale(200), kHeightScale(30))];
    titleLbl.text = @"会议详情";
    [titleLbl setFont:[UIFont fontWithName:@"Helvetica-Bold" size:17]];
    titleLbl.textColor = [UIColor whiteColor];
    titleLbl.textAlignment = NSTextAlignmentCenter;
    [navBackView addSubview:titleLbl];
    _navTitleLbl = titleLbl;
    
    UIView *backHeadView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidthScale(200), kHeightScale(30))];
    
    UIButton *titleBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, kHeightScale(5), kWidthScale(200), kHeightScale(18))];
    [titleBtn setTitle:@"索大大😁😄" forState:UIControlStateNormal];
    titleBtn.titleLabel.font = [UIFont systemFontOfSize:kWidthScale(15)];
    UIButton *userHead = [[UIButton alloc] initWithFrame:CGRectMake(kWidthScale(30), kHeightScale(6), kWidthScale(18), kHeightScale(18))];
    [userHead setImage:[UIImage imageNamed:@"toixiang"] forState:0];
    
    [backHeadView addSubview:titleBtn];
    [backHeadView addSubview:userHead];
    [navBackView addSubview:backHeadView];
    _headView = backHeadView;
    // 先让带图片的导航视图隐藏
    _headView.alpha = 0;
    
    _borderNum = 15.f;
    _firstComeInNum = 0;
    
    //表格设置
    [self.view addSubview:self.tableView];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;// 去掉所有cell的分割线
    
}
- (void)clickLeftBarButton
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)clickRightButton
{
    
}

//返回每个分区下的单元格个数，必须实现
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return kHeightScale(879);
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * str= @"biao";
    QualitycreationdetailsTableViewNBCell*cell=[tableView dequeueReusableCellWithIdentifier:str];
    if (!cell) {
        
        cell=[[QualitycreationdetailsTableViewNBCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }
    cell.selectionStyle=UITableViewStylePlain;
    return cell;
}
- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, UIScreenHeight+40) style:UITableViewStylePlain];
        
        _tableView.delegate = self;
        
        _tableView.dataSource = self;
    }
    return _tableView;
}
#pragma mark -导航条设置
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    _firstComeInNum ++;
    NSLog(@"%ld",(long)_firstComeInNum);
    if (_firstComeInNum >2) {
        // 表格 y 的滑动位置
        CGFloat contentOffset = scrollView.contentOffset.y +64;
        //NSLog(@"contentOffset :%lf",contentOffset);
        if (contentOffset <0.f) { // y的位置小于0 ，不进行下面的操作 直接退出该方法
            return;
        } else if (contentOffset <_borderNum) { // y 小于 64 ，则显示 titleLbl ，并根据y的大小来改变titleLbl的透明度
            _navTitleLbl.alpha = (_borderNum - contentOffset )/ _borderNum;
            _headView.alpha = 0.f;
        } else if (contentOffset >_borderNum) {
            _navTitleLbl.alpha = 0.f;
            _headView.alpha = (contentOffset -_borderNum )/_borderNum;
        } else if (contentOffset == _borderNum) {
            _navTitleLbl.alpha = 0.f;
            _headView.alpha = 0.f;
        }
        //NSLog(@"%lf",contentOffset);
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
